home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / statgen / rare.nawk < prev    next >
Encoding:
Text File  |  1991-12-18  |  5.2 KB  |  221 lines

  1. #! /bin/sh
  2.  
  3. nawk '
  4. BEGIN { FS = "|"
  5.     days[0] = 0
  6.     days[1] = 31
  7.     days[2] = days[1] + 28
  8.     days[3] = days[2] + 31
  9.     days[4] = days[3] + 30
  10.     days[5] = days[4] + 31
  11.     days[6] = days[5] + 30
  12.     days[7] = days[6] + 31
  13.     days[8] = days[7] + 31
  14.     days[9] = days[8] + 30
  15.     days[10] = days[9] + 31
  16.     days[11] = days[10] + 30
  17.     days[12] = days[11] + 31
  18. }
  19.     { ctime = $1
  20.       if(!starttime)
  21.         starttime = ctime
  22.     }
  23. $2 == "Deliv" {
  24. # Format
  25. # date-time|Deliv|msgid|inchan|outchan|p1id|size|sender|inmta|recip|outmta|
  26. # 1         2     3     4      5       6    7    8      9     10    11
  27. # sub-time|queue-time
  28. # 12       13
  29.     mtaout = $11
  30.     size = $7
  31.     msg = $3
  32.     queuetime = $13
  33.     storeit(mtaout, msg, queuetime, size)
  34.     next
  35. }
  36. $2 == "DR" {
  37. # Format
  38. # date-time|DR|type|msgid|p1id|size|inchan|dest|inhost|outchan|src|host|
  39. # 1         2  3    4     5    6    7      8    9      10      11  12
  40. # cchan|reason|diag|mesg
  41. # 13    14     15   16
  42. # cchan|submit-time|queued-time
  43. # 13    14        15
  44.  
  45.     msg = $4
  46.     mtain = $8
  47.     mtaout = $12
  48.     type = $3
  49.     queuetime = $15
  50.     size = $6
  51.     if (type == "negative") {
  52.     #    storeit(mtaout, msg, queuetime,size)
  53.         drsnegative ++
  54.     } else if (type == positive) {
  55.         storeit(mtaout, msg, queuetime, size)
  56.         drspositive ++
  57.     } else if (type == "transit") {
  58.         drsin ++;
  59.         drsmta[mtain] ++
  60.     }
  61.     next
  62. }
  63. $2 == "ok" {
  64. # Format
  65. # date-time|ok|msgid|inchan|outchan|p1id|size|sender|inmta|recip|outmta|
  66. # 1        2  3     4        5        6     7    8         9     10    11
  67. # msg|submit-time
  68. # 12  13
  69.     mtain = $9
  70.     msg = $3
  71.     size = $7
  72.     mtaout = $11
  73.     if(mtamsgin[mtain msg] == 0) {
  74.         mtamsgin[mtain msg] = 1
  75.         if (mtainbytes[mtain] == 0) {
  76.             n = split(mtain, parts, ".")
  77.             if (n > 1)
  78.                 domcom[mtain] = parts[n]
  79.             else    domcom[mtain] = "local"
  80.         }
  81.         mtainbytes[mtain] += size
  82.         mtainnumb[mtain] ++
  83.     }
  84.     next
  85. }
  86.     { error( "ignore line " NR $0) }
  87. func error(mesg) {
  88.     print mesg | "cat 1>&2"
  89. }
  90.  
  91. func storeit(mtaout, msg, queuetime,size) {
  92.     if (mtamsgout[mtaout msg] == 0){
  93.         mtamsgout[mtaout msg] = 1
  94.         if (mtaoutbytes[mtaout] == 0) {
  95.             n = split(mtaout, parts, ".")
  96.             if (n > 1)
  97.                 domcom[mtaout] = parts[n]
  98.             else    domcom[mtaout] = "local"
  99.         }
  100.         mtaoutbytes[mtaout] += size
  101.         mtaoutnumb[mtaout] ++
  102.  
  103.         n = tdiff(queuetime, ctime)
  104.         for (i = n; i <= 5; i++)
  105.             elapsed[mtaout i] ++
  106.     }
  107. }
  108. func line(c, n,        i, str) {
  109.     for (i = 0; i < n; i++)
  110.         str = str c
  111.     print str
  112. }
  113. func percent(a,b) {
  114.     if (b == 0) return 0;
  115.     return a * 100 / b
  116. }
  117. func tdiff(t1,t2,    diff,time1,time2) {
  118.     split(t1, t1pts, ":")
  119.     split(t2, t2pts, ":")
  120.     time1 = days[t1pts[1]-1] * 24 * 3600
  121.     time1 += t1pts[2] * 24 * 3600
  122.     time1 += t1pts[3] * 3600
  123.     time1 += t1pts[4] * 60
  124.     time1 += t1pts[5]
  125.     time2 = days[t2pts[1]-1] * 24 * 3600
  126.     time2 += t2pts[2] * 24 * 3600
  127.     time2 += t2pts[3] * 3600
  128.     time2 += t2pts[4] * 60
  129.     time2 += t2pts[5]
  130.     diff = time2 - time1
  131.     if (diff < 60)
  132.         return 1
  133.     else if (diff < 5 * 60)
  134.         return 2
  135.     else if (diff < 3600)
  136.         return 3
  137.     else if (diff  < 3600*24)
  138.         return 4
  139.     else return 5
  140. }
  141. END {
  142.     line("=", 80)
  143.     split(starttime, part1, ":")
  144.     split(ctime, part2, ":")
  145.     msg = sprintf(\
  146.         "Statistics from %s/%s %d:%02d:%02d to %s/%s %d:%02d:%02d",\
  147.         part1[1], part1[2], part1[3], part1[4], part1[5],\
  148.         part2[1], part2[2], part2[3], part2[4], part2[5])
  149.     printf "%" (length(msg) - 80) / 2 "s%s\n", "", msg
  150.     line("=",80)
  151.     msg = "Inbound statistics"
  152.     print "\n\n"
  153.     print msg
  154.     line("-", length(msg))
  155.     print "\n\nSource"
  156.     partner = "Partner"
  157.     MTA = "MTA"
  158.     wid = length(MTA)
  159.     for (i in mtainnumb)
  160.         if (length(i) > wid)
  161.             wid = length(i)
  162.     wid2 = length(partner)
  163.     for (i in domcom)
  164.         if (length(domcom[i]) > wid2)
  165.             wid2 = length(domcom[i])
  166.     printf "%-" wid2 "s %-" wid "s %8s %10s\n", partner,\
  167.             MTA, "#messg", "#kByte"
  168.     line("-", 80)
  169.     for (i in mtainnumb) {
  170.         printf "%-" wid2 "s %-" wid "s %8d %10.2f\n", domcom[i], i,\
  171.             mtainnumb[i], mtainbytes[i]/1000
  172.         totbytes += mtainbytes[i]/1000.0
  173.         totmsgs += mtainnumb[i]
  174.     }
  175.     line("-", 80)
  176.     printf "%-" wid + wid2 "s  %8d %10.2f\n", "Total", totmsgs, totbytes
  177.  
  178.     msg = "Outbound statistics"
  179.     print "\n\n"
  180.     print msg
  181.     line("-", length(msg))
  182.     wid = length(MTA)
  183.     for (i in mtaoutnumb)
  184.         if (length(i) > wid)
  185.             wid = length(i)
  186.  
  187.     printf "\n\n%-" wid + wid2 + 28 "s %s\n", "", \
  188.             "% of messages"
  189.     printf "%-" wid + wid2 + 27 "s %s\n", "Destination", "relayed within"
  190.     printf "%-" wid2 "s %-" wid "s %8s %10s  %4s %4s %4s %4s\n", \
  191.         partner, MTA, "#messg", "#kByte", "1m", "5m", "1h", "1d"
  192.     totbytes = totmsgs = 0
  193.     line("-", 80)
  194.     for (i in mtaoutnumb) {
  195.         printf "%-" wid2 "s %-" wid "s %8d %10.2f  %4d %4d %4d %4d\n",\
  196.             domcom[i], i, mtaoutnumb[i], mtaoutbytes[i]/1000,\
  197.             percent(elapsed[i 1], mtaoutnumb[i]), \
  198.             percent(elapsed[i 2], mtaoutnumb[i]), \
  199.             percent(elapsed[i 3], mtaoutnumb[i]), \
  200.             percent(elapsed[i 4], mtaoutnumb[i])
  201.         for (j = 1; j < 5; j++)
  202.             telapsed[j] += elapsed[i j]
  203.         totbytes += mtaoutbytes[i]/1000
  204.         totmsgs += mtaoutnumb[i]
  205.     }
  206.     line("-", 80)
  207.     printf "%-" wid + wid2 "s  %8d %10.2f  %4d %4d %4d %4d\n\n", \
  208.             "Total", totmsgs, totbytes, \
  209.             percent(telapsed[1], totmsgs), \
  210.             percent(telapsed[2], totmsgs), \
  211.             percent(telapsed[3], totmsgs), \
  212.             percent(telapsed[4], totmsgs)
  213.  
  214.     if (drspositive || drsnegative)
  215.         printf "Delivery reports generated: %d positive, %d negative\n", \
  216.         drspositive, drsnegative
  217.     if (drsin) 
  218.         printf "Delivery reports relayed: %d\n", drsin
  219. }
  220. ' $*
  221.